<?php

/**
 * @author edson
 * @copyright 2011
 *  clase que maneja el logeo y todo lo relacionado a "ADMINISTRACION DE VENTANAS PARA USUARIOS" 
 * 
 */

 //establecer una variable conratafisica $_LOCALHOST
$ruta=$_SERVER['DOCUMENT_ROOT']."/viventura"."/MDOperator";
include_once("$ruta/star.php");
//include_once("$rut/conf/CConfig.php");

if (!isset($_GET['update'])) {$_GET['update'] = "NULL"; }
$update = $_GET['update'];


if (!isset($_GET['codigo'])) {$_GET['codigo'] = "NULL"; }
$idOpe = $_GET['codigo'];


if (!isset($_GET['servicio'])) {$_GET['servicio'] = "NULL"; }
$servicio = $_GET['servicio'];

if (!isset($_GET['servicioupd'])) {$_GET['servicioupd'] = "NULL"; }
$servicioupd = $_GET['servicioupd'];

if (!isset($_POST['NamOpe'])) {$_POST['NamOpe'] = "NULL"; }
if (!isset($_POST['DirOpe'])) {$_POST['DirOpe'] = "NULL"; }
if (!isset($_POST['CodPosOpe'])) {$_POST['CodPosOpe'] = "NULL"; }
if (!isset($_POST['WebSitOpe'])) {$_POST['WebSitOpe'] = "NULL"; }
if (!isset($_POST['FirstConOpe'])) {$_POST['FirstConOpe'] = "NULL"; }
if (!isset($_POST['LastConOpe'])) {$_POST['LastConOpe'] = "NULL"; }
if (!isset($_POST['DirOpe'])) {$_POST['DirOpe'] = "NULL"; }
if (!isset($_POST['PhoOpe'])) {$_POST['PhoOpe'] = "NULL"; }
if (!isset($_POST['MailOpe'])) {$_POST['MailOpe'] = "NULL"; }
if (!isset($_POST['CommOpe'])) {$_POST['CommOpe'] = "NULL"; }
if (!isset($_POST['WebSitOp'])) {$_POST['WebSitOp'] = "NULL"; }
if (!isset($_POST['FaxOpe'])) {$_POST['FaxOpe'] = "NULL"; }
if (!isset($_POST['ClasOpe'])) {$_POST['ClasOpe'] = "NULL"; }
if (!isset($_POST['idCit'])) {$_POST['idCit'] = "NULL"; }



$NamOpe=$_POST['NamOpe'];
$DirOpe=$_POST['DirOpe'];
$CodPosOpe=$_POST['CodPosOpe'];
$WebSitOp=$_POST['WebSitOp'];
$FirstConOpe=$_POST['FirstConOpe'];
$LastConOpe=$_POST['LastConOpe'];
$DirOpe=$_POST['DirOpe'];
$PhoOpe=$_POST['PhoOpe'];
$MailOpe=$_POST['MailOpe'];
$CommOpe=$_POST['CommOpe'];
$FaxOpe=$_POST['FaxOpe'];
$ClasOpe=$_POST['ClasOpe'];
$idCit=$_POST['idCit'];



//-------------------------------------------------
//validacion de usuarios 

$cadena="insert into operador (IdOpe, NamOpe, CITY_idCit,  CodPosOpe, FirstConOpe, LastConOp,WebSitOp,DirOpe,PhoOpe,MailOpe,CommOpe,ClasOpe)
         values ('NULL','$NamOpe',$idCit,'$CodPosOpe','$FirstConOpe','$LastConOpe','$WebSitOp','$DirOpe','$PhoOpe', '$MailOpe', '$CommOpe', '$ClasOpe')";


// $cadena="insert into operador ('IdOpe', 'NamOpe', 'DirOpe',)
 // values ('NULL','$NamOpe','$DirOpe','$CodPosOpe','$FirstConOpe','$LastConOpe','$WebSitOpe','$DirOpe','$PhoOpe')";
    $table=CModelo::getInstance()->insertData($cadena);
    
  

if($update==1){
    $sql = "UPDATE  `viv`.`operador` SET  
            `FirstConOpe` =  '$FirstConOpe',
            `LastConOpe` =  '$LastConOpe',
            `MailOpe` =  '$MailOpe',
            `PhoOpe` =  '$PhoOpe',
            `FaxOpe` =  '$FaxOpe',
            `CodPosOpe` =  '$CodPosOpe',
            `WebSitOp` =  '$WebSitOp',
            `NamOpe` =  '$NamOpe' WHERE  `operador`.`idOpe` = $idOpe;";

    CModelo::getInstance()->insertData($sql);
}



if($servicio==1){
    
    if (!isset($_POST['multi'])) {$_POST['multi'] = "NULL"; }
    if (!isset($_POST['idOpe'])) {$_POST['idOpe'] = "NULL"; }
    if (!isset($_POST['DesRes'])) {$_POST['DesRes'] = "NULL"; }
    if (!isset($_POST['CanIteRec'])) {$_POST['CanIteRec'] = "NULL"; }
    if (!isset($_POST['PriUni'])) {$_POST['PriUni'] = "NULL"; }
    if (!isset($_POST['CommSer'])) {$_POST['CommSer'] = "NULL"; }
    if (!isset($_POST['DesSer'])) {$_POST['DesSer'] = "NULL"; }    
    if (!isset($_POST['opcion_act'])) {$_POST['opcion_act'] = "NULL"; } 
    
    $opcion_act =$_POST['opcion_act'];
    echo $opcion_act;    
    $idOpe =$_POST['idOpe'];
    $DesSer=$_POST['DesSer'];
    $CanIteRec=$_POST['CanIteRec'];    
    $PriUni=$_POST['PriUni'];
    //$PriUni = number_format($PriUni, 2, ',', '');
    $CommSer=$_POST['CommSer'];
    $services_list=$_POST['multi'];
    
    
    
    if (!isset($_POST['idAct'])) {$_POST['idAct'] = "NULL"; }
    if (!isset($_POST['NomAct'])) {$_POST['NomAct'] = "NULL"; }
    if (!isset($_POST['DescAct'])) {$_POST['DescAct'] = "NULL"; }
    if (!isset($_POST['PlaceAct'])) {$_POST['PlaceAct'] = "NULL"; }
    if (!isset($_POST['HourAct'])) {$_POST['HourAct'] = "NULL"; }
    if (!isset($_POST['ChargeAct'])) {$_POST['ChargeAct'] = "NULL"; }
    
    $idAct = $_POST['idAct'];
    $NomAct = $_POST['NomAct'];
    $DescAct = $_POST['DescAct'];
    $PlaceAct = $_POST['PlaceAct'];
    $HourAct = $_POST['HourAct'];
    $ChargeAct = $_POST['ChargeAct'];
    
        
    if($servicioupd==1){
        $qu = "UPDATE  `transporte_has_pack_has_tour` SET  
              `DesSer` =  '$DesSer',
              `CommSer` =  '$CommSer',
              `CanIteRec` =  '$CanIteRec',
              `PriUni` =  '$PriUni' WHERE  `TranPackTour` = '$idTranPackTourUpd'";
        CModelo::getInstance()->insertData($qu);    
        
        $qu2 = "Select `transporte_idTrans` from transporte_has_pack_has_tour where `TranPackTour` =$idTranPackTourUpd" ;
      
        $ans = CModelo::getInstance()->getData($qu2);
        foreach ($ans as $r => $c){ $ans2 = $c; foreach ($ans2 as $r1 => $c1 ){ $idTran = $c1;}}

        echo "<script> parent.location.href = 'MDTransporteServicio/CResumeServices.php?codigo=$idTran'</script>";
        }
        
    else{
        if($opcion_act>=1){
             $qu = "insert into actividades_has_tour_has_pasajero (operador_idOpe,DesSer,CanIteRec,PriUni,CommSer,SerFlag,actividades_idAct) 
             values ('$idOpe','$DesSer','$CanIteRec','$PriUni','$CommSer','1','$opcion_act')";
             $idt = CModelo::getInstance()->insertData($qu);
        }
        else{
        $reg_act= "INSERT INTO `actividades` (`idAct` ,`NomAct` ,`DescAct` ,`PlaceAct` ,`HourAct` ,`ChargeAct`)
                   VALUES (NULL ,  '$NomAct',  '$DesSer',  '$PlaceAct', NULL ,  '$ChargeAct')";
        $idActInserted  = CModelo::getInstance()->insertData($reg_act);
         
        $qu = "insert into actividades_has_tour_has_pasajero (operador_idOpe,DesSer,CanIteRec,PriUni,CommSer,SerFlag,actividades_idAct) 
        values ('$idOpe','$DesSer','$CanIteRec','$PriUni','$CommSer','1','$idActInserted')";
        $idt = CModelo::getInstance()->insertData($qu);
        }
    }
    
    
    //MDOperatorServicio/CResumeServices.php?codigo=1313
    echo "<script> parent.location.href = '../MDOperatorServicio/CResumeServices.php?codigo=$idOpe' </script>";
 
}





  //echo "<script> parent.location.href = '../index.php' </script>";

?>
